package com.boot.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


public class BasePathInterceptor extends HandlerInterceptorAdapter {
	private static Logger logger = Logger.getLogger(BasePathInterceptor.class);

	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String scheme = request.getScheme();
		// logger.info("scheme="+scheme);
		String serverName = request.getServerName();
		// logger.info("服务名serverName="+serverName);
		int port = request.getServerPort();
		// logger.info("端口port="+port);
		String path = request.getContextPath();
		request.setCharacterEncoding("utf-8");
		String basePath = scheme + "://" + serverName + ":" + port + path;
		
		logger.info("absoluty_path:" + basePath);
		request.setAttribute("root", basePath);
		return true;
	}

}
